from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `idcard_info` DROP COLUMN `valid_period`;
        ALTER TABLE `idcard_info` DROP COLUMN `issuing_authority`;
        ALTER TABLE `idcard_info` DROP COLUMN `address`;
        ALTER TABLE `idcard_info` DROP COLUMN `ethnicity`;
        ALTER TABLE `idcard_info` MODIFY COLUMN `birth_date` VARCHAR(50)   COMMENT '出生日期';
        ALTER TABLE `idcard_info` MODIFY COLUMN `name` VARCHAR(50) NOT NULL  COMMENT '姓名';
        ALTER TABLE `idcard_info` MODIFY COLUMN `user_id` INT NOT NULL  COMMENT '关联用户';
        ALTER TABLE `idcard_info` MODIFY COLUMN `idcard_number` VARCHAR(18) NOT NULL  COMMENT '身份证号';
        ALTER TABLE `idcard_info` MODIFY COLUMN `gender` VARCHAR(10)   COMMENT '性别';
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `refresh_token` VARCHAR(500);
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `provider_user_id` VARCHAR(255) NOT NULL;
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `access_token` VARCHAR(500);
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `provider` VARCHAR(32) NOT NULL;
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `user_id` INT NOT NULL;
        ALTER TABLE `sport_types` MODIFY COLUMN `default_pace_unit` VARCHAR(10) NOT NULL  COMMENT '默认配速单位' DEFAULT 'min/km';
        ALTER TABLE `sport_types` MODIFY COLUMN `code` VARCHAR(50) NOT NULL  COMMENT '内部代码（例：outdoor_run）';
        ALTER TABLE `sport_types` MODIFY COLUMN `name_cn` VARCHAR(50) NOT NULL  COMMENT '中文名称（例：户外跑）';
        ALTER TABLE `users` MODIFY COLUMN `username` VARCHAR(64) NOT NULL;
        ALTER TABLE `users` MODIFY COLUMN `avatar` VARCHAR(500);
        ALTER TABLE `users` MODIFY COLUMN `password` VARCHAR(255);
        ALTER TABLE `users` MODIFY COLUMN `phone` VARCHAR(20);
        ALTER TABLE `users` MODIFY COLUMN `email` VARCHAR(255);
        ALTER TABLE `user_training_records` MODIFY COLUMN `sport_type_id` INT NOT NULL  COMMENT '关联的运动类型ID';"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `users` MODIFY COLUMN `username` VARCHAR(64) NOT NULL;
        ALTER TABLE `users` MODIFY COLUMN `avatar` VARCHAR(500);
        ALTER TABLE `users` MODIFY COLUMN `password` VARCHAR(255);
        ALTER TABLE `users` MODIFY COLUMN `phone` VARCHAR(20);
        ALTER TABLE `users` MODIFY COLUMN `email` VARCHAR(255);
        ALTER TABLE `sport_types` MODIFY COLUMN `default_pace_unit` VARCHAR(10) NOT NULL  COMMENT '默认配速单位' DEFAULT 'min/km';
        ALTER TABLE `sport_types` MODIFY COLUMN `code` VARCHAR(50) NOT NULL  COMMENT '内部代码（例：outdoor_run）';
        ALTER TABLE `sport_types` MODIFY COLUMN `name_cn` VARCHAR(50) NOT NULL  COMMENT '中文名称（例：户外跑）';
        ALTER TABLE `idcard_info` ADD `valid_period` VARCHAR(100)   COMMENT '有效期限';
        ALTER TABLE `idcard_info` ADD `issuing_authority` VARCHAR(100)   COMMENT '签发机关';
        ALTER TABLE `idcard_info` ADD `address` VARCHAR(255)   COMMENT '地址';
        ALTER TABLE `idcard_info` ADD `ethnicity` VARCHAR(20)   COMMENT '民族';
        ALTER TABLE `idcard_info` MODIFY COLUMN `birth_date` VARCHAR(50)   COMMENT '出生日期';
        ALTER TABLE `idcard_info` MODIFY COLUMN `name` VARCHAR(50) NOT NULL  COMMENT '姓名';
        ALTER TABLE `idcard_info` MODIFY COLUMN `user_id` INT NOT NULL  COMMENT '关联用户';
        ALTER TABLE `idcard_info` MODIFY COLUMN `idcard_number` VARCHAR(18) NOT NULL  COMMENT '身份证号';
        ALTER TABLE `idcard_info` MODIFY COLUMN `gender` VARCHAR(10)   COMMENT '性别';
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `refresh_token` VARCHAR(500);
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `provider_user_id` VARCHAR(255) NOT NULL;
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `access_token` VARCHAR(500);
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `provider` VARCHAR(32) NOT NULL;
        ALTER TABLE `oauth_accounts` MODIFY COLUMN `user_id` INT NOT NULL;
        ALTER TABLE `user_training_records` MODIFY COLUMN `sport_type_id` INT NOT NULL  COMMENT '关联的运动类型ID';"""
